﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ItemsControl.cs" company="">
//   
// </copyright>
// <summary>
//   The items control.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.Controls
{
    using System;
    using System.Windows.Forms;

    using Libium.Views;

    /// <summary>
    /// The items control.
    /// </summary>
    public partial class ItemsControl : BindableUserControl, IItemsView
    {
        // List<Control> 
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ItemsControl"/> class.
        /// </summary>
        public ItemsControl()
        {
            InitializeComponent();
        }

        #endregion

        // protected virtual IEnumerable<Control> ItemControls
        // {
        // 	get { return Controls.Cast<Control>(); }
        // }
        #region Public Methods and Operators

        /// <summary>
        /// The add item view.
        /// </summary>
        /// <param name="typeName">
        /// The type name.
        /// </param>
        /// <param name="itemControl">
        /// The item control.
        /// </param>
        /// <returns>
        /// The <see cref="Control"/>.
        /// </returns>
        public virtual Control AddItemView(string typeName, Control itemControl)
        {
            Controls.Add(itemControl);
            return itemControl;
        }

        /// <summary>
        /// The add item view.
        /// </summary>
        /// <param name="itemControl">
        /// The item control.
        /// </param>
        /// <returns>
        /// The <see cref="Control"/>.
        /// </returns>
        public Control AddItemView(Control itemControl)
        {
            return AddItemView(string.Empty, itemControl);
        }

        /// <summary>
        /// The add item view.
        /// </summary>
        /// <param name="typeName">
        /// The type name.
        /// </param>
        /// <returns>
        /// The <see cref="Control"/>.
        /// </returns>
        public Control AddItemView(string typeName)
        {
            var itemControl = CreateItemControl(typeName);
            return AddItemView(typeName, itemControl);
        }

        /// <summary>
        /// The delete item view.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public virtual void DeleteItemView(Control view)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region Explicit Interface Methods

        /// <summary>
        /// The add item view.
        /// </summary>
        /// <param name="typeName">
        /// The type name.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        object IItemsView.AddItemView(string typeName)
        {
            return AddItemView(typeName);
        }

        /// <summary>
        /// The delete item view.
        /// </summary>
        /// <param name="view">
        /// The view.
        /// </param>
        void IItemsView.DeleteItemView(object view)
        {
            DeleteItemView((Control)view);
        }

        #endregion

        #region Methods

        /// <summary>
        /// The create item control.
        /// </summary>
        /// <param name="typeName">
        /// The type name.
        /// </param>
        /// <returns>
        /// The <see cref="Control"/>.
        /// </returns>
        /// <exception cref="NotImplementedException">
        /// </exception>
        protected virtual Control CreateItemControl(string typeName)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}